package com.livestocksolutions.ui;

import java.util.Date;

import com.livestocksolutions.R;
import com.livestocksolutions.intent.BaseActivity;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/* -- Version History --
 *  1.0 : 29 July 2012 - Initial version.
 *  
 *  1.1 : 09 September 2012 - Class now extends ViewCattleArrayAdapter
 */

/**
 * A class to create the layout for the list of cattle
 * @author Adam Parr
 * @version 1.0
 * 
 * @.modified 19 October 2012
 */
public class ListCattleArrayAdapter extends ViewCattleArrayAdapter { 
	/**
	 * Size of the allowable array passed
	 */
	public static final int SIZE = 4;
	
	/**
	 * Constructor
	 * @param context The current context.
	 * @param values The Bovines to represent in the ListView.
	 */
	public ListCattleArrayAdapter(BaseActivity context, String[][] values) {
		super(context, values);
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		setView(R.layout.list_item_cattle);
		View rowView = super.setView(position,convertView,parent);

		TextView cattleVisTag = (TextView) rowView.findViewById(R.id.cattleVisTag);
		TextView cattleRFID = (TextView) rowView.findViewById(R.id.cattleRFID);
		TextView cattleWithholdPeriod = (TextView) rowView.findViewById(R.id.cattleWithholdPeriod);

		values[position][VISUALID] = values[position][VISUALID]!=null && values[position][VISUALID].length()>0?values[position][VISUALID]:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_noTag));
		values[position][NLISRFID] = values[position][NLISRFID]!=null && values[position][NLISRFID].length()>0?values[position][NLISRFID]:context.getResources().getString(R.string.message_noText,context.getResources().getString(R.string.message_noTag));
		
		cattleVisTag.setText(values[position][VISUALID]);
		cattleRFID.setText(values[position][NLISRFID]);
		if(cattleWithholdPeriod!=null){
			Date dob = context.parse(values[position][DOB]);
			cattleWithholdPeriod.setText(dob!=null?context.format(dob):context.getResources().getString(R.string.message_notKnown));
		}
		return rowView;
	}
}
